package com.weaver.qfengx.api.ding;

import java.util.*;

public class DingApiServiceUtils {

    /**
     * 发送群消息封装
     * @param unionid 服务号
     * @param imgUrl 图片URL
     * @param imgTitle 图片标题
     * @param title 消息显示表示
     * @param summary 内容渐渐
     * @param actionName 动作名称
     * @param msgurl 消息跳转URL
     * @param btnTitle 按钮标题
     * @param useridlist 接收用户
     * @param depidlist 接收部门
     * @param apiServiceHttpClient ApiClient
     * @param token 令牌
     * @return
     * @throws Exception
     */
    public static DingApiHttpClientResult sendMsg(String unionid, String imgUrl, String imgTitle, String title, String summary, String actionName,
                                                  String btnTitle,
                                                  String msgurl, String useridlist, String depidlist,
                        DingApiServiceHttpClient apiServiceHttpClient, String token) throws Exception {
        // 发送服务窗消息
        Map<String, Object> msg_body = new HashMap<>();
        Map<String, Object> info = new HashMap<>();
        info.put("btn_orientation", "1");
        Map<String, String> button_list = new HashMap<>();
        button_list.put("action_url", msgurl);
        button_list.put("title", btnTitle);
        List<Map<String, String>> btnList = new ArrayList<>();
        btnList.add(button_list);
        info.put("button_list", btnList);
        info.put("title", title);
        info.put("markdown", String.format("![%s](%s)\n\n" +
                "##### %s\n" +
                "##### %s\n", imgTitle, imgUrl, summary, actionName));
        msg_body.put("action_card", info);
        return apiServiceHttpClient.massSend(token, unionid,
                "", false,
                "action_card", "", UUID.randomUUID().toString().replace("-", ""),
                useridlist, depidlist, false, msg_body);
    }

}
